home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 21
/
Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso
/
Aminet
/
util
/
cdity
/
availmem2.lha
/
AvailMem2
/
src
/
AvailMem2_bar.s
next >
Wrap
Text File
|
1997-07-01
|
15KB
|
630 lines
machine 68020
* program includes
include "AvailMem2_gui.i"
include "AvailMem2.i"
include "lvo.i"
incdir "include:"
include "exec/types.i"
include "exec/memory.i"
include "exec/funcdef.i"
include "graphics/gfx.i"
include "intuition/intuition.i"
* program structures
STRUCTURE mb_Main,0 ;memory-bar structure
LONG mb_Rport
LONG mb_XPos
LONG mb_YPos
LONG mb_XWidth
LONG mb_YHeight
LONG mb_OldMemFree
LABEL mb_SIZEOF
section code,code ;availmem code section
_RenderBars
* * * * * * * * * * * * * * * * * * * * *
* *
* Renders the memory-bars. *
* *
* * * * * * * * * * * * * * * * * * * * *
movem.l d0-a6,-(sp) ;push all registers
lea.l _BarList,a4 ;get ptr to bars
.RenderBars
move.l (a4)+,a0 ;get ptr to next bar-checkvar
move.l a0,d0 ;put addr in d0
tst.l d0 ;check if it IS a bar-var
beq .NoBarsLeft ;end looping if not
move.l (a0),d0 ;get checkvar state
move.l (a4)+,a5 ;get ptr of bar into a5
move.l (a4)+,d3 ;get memory-attrs
move.l (a4)+,d1 ;get bar type
tst.l d1 ;check if this is a CPU bar
bne .is_CPU ;skip if so
tst.l d0 ;check if i should render bar
beq .no_refresh ;skip if not
move.l (4).w,a6
move.l d3,d1 ;get total amount of free mem
jsr _LVOAvailMem(a6) ;get mem free
move.l d0,d5 ;put result in d5
cmp.l mb_OldMemFree(a5),d5 ;check if the memory has changed
beq .no_refresh ;skip if not
move.l d5,mb_OldMemFree(a5) ;change amount of mem free
move.l (4).w,a6 ;put execbase in a6
move.l #MEMF_LARGEST,d1 ;get largest amount of free mem
or.l d3,d1 ;add specific attributes
jsr _LVOAvailMem(a6) ;get largest block of memory
move.l d0,d6 ;put largest block in d6
move.l (4).w,a6 ;put execbase in a6
move.l #MEMF_TOTAL,d1
or.l d3,d1 ;add specific attributes
jsr _LVOAvailMem(a6) ;get total amount of publicmem
move.l d0,d7 ;put total amount of mem in d7
tst.l d7 ;check if publicmem is present
beq .no_refresh ;skip if not
move.l a5,a0 ;get ptr of publicmem bar into a0
move.l d5,d0 ;put free mem in d0
move.l d6,d1 ;put largest block in d1
move.l d7,d2 ;put total amount of mem in d2
jsr _RenderMemoryBar ;render memory bar
.no_refresh
bra .RenderBars ;loop rendering
.is_CPU
tst.l d0 ;check if i should render bar
beq .no_refresh ;skip if not
move.l d1,a0 ;put ptr to cpu usage in a0
move.l (a0),d0 ;put cpu usage in d0
move.l #-1,(a0) ;reset usage
tst.l d0 ;check if i should update
bmi .no_refresh ;skip if not
move.l d0,d1
move.l a5,a0 ;get ptr of cpuusage bar into a0
move.l #101,d2 ;put maximum in d2
jsr _RenderMemoryBar ;render CPU bar
bra .RenderBars ;loop rendering
.NoBarsLeft
movem.l (sp)+,d0-a6
rts
_CalculateBars
* * * * * * * * * * * * * * * * * * * * *
* *
* Calculates how the memory-bars should *
* be displayed in the window. *
* *
* * * * * * * * * * * * * * * * * * * * *
movem.l d0-a6,-(sp) ;push all registers
clr.l d7 ;reset number of bars
tst.l prg_ChipDisplayed ;check if chip should be displayed
beq .no_chipmem_added ;skip if not
add.l #1,d7 ;increase bar-counter
.no_chipmem_added
tst.l prg_FastDisplayed ;check if fast should be displayed
beq .no_fastmem_added ;skip if not
add.l #1,d7 ;increase bar-counter
.no_fastmem_added
tst.l prg_PublicDisplayed ;check if public should be displayed
beq .no_publicmem_added ;skip if not
add.l #1,d7 ;increase bar-counter
.no_publicmem_added
tst.l prg_CPUDisplayed ;check if CPU should be displayed
beq .no_CPU_added ;skip if not
add.l #1,d7 ;increase bar-counter
.no_CPU_added
tst.l d7 ;check if any bars added
beq .Fail :skip if not
move.l _GfxBase,a6 ;put gfxbase in a6
move.l MemoryDisplayWnd,a1 ;put ptr to mem-display window in a1
move.l wd_RPort(a1),a1 ;put win rastport in a1
move.l #0,d0 ;set colour to zero
jsr _LVOSetRast(a6) ;flush window
move.l MemoryDisplayWnd,a1 ;put ptr to mem-display window in a1
move.w wd_GZZHeight(a1),d0 ;get height of window
ext.l d0 ;extend to longword
divs.w d7,d0 ;divide height within bars
move.l d0,d4 ;set y-adder
sub.l #2,d0 ;keep away from borders
move.l d0,d3 ;set bar initial height
cmp.l #10,d0 ;check if bar-height<10
blo .Fail ;skip if true
move.w wd_GZZWidth(a1),d0 ;put window width in d0
sub.w #4,d0 ;substract minimum plain area
ext.l d0 ;extend to longword
move.l d0,d2 ;put bar-area in d2
move.l wd_RPort(a1),a1 ;get window rast-port into a1
move.l #2,d0 ;set bar initial x-pos
move.l #1,d1 ;set bar initial y-pos
tst.l prg_ChipDisplayed ;check if chip-bar should be displayed
beq .no_chipbar ;skip if not
lea.l prg_ChipmemBar,a0 ;get ptr to chipbar into a0
jsr _InitializeBar ;initalize fast-bar
add.l d4,d1 ;increase y
.no_chipbar
tst.l prg_FastDisplayed ;check if fast-bar should be displayed
beq .no_fastbar ;skip if not
lea.l prg_FastmemBar,a0 ;get ptr to fastbar into a0
jsr _InitializeBar ;initalize fast-bar
add.l d4,d1 ;increase y
.no_fastbar
tst.l prg_PublicDisplayed ;check if public-bar should be displayed
beq .no_publicbar ;skip if not
lea.l prg_PublicmemBar,a0 ;get ptr to publicbar into a0
jsr _InitializeBar ;initalize public-bar
add.l d4,d1 ;increase y
.no_publicbar
tst.l prg_CPUDisplayed ;check if cpu-bar should be displayed
beq .no_cpubar ;skip if not
lea.l prg_CPUUsageBar,a0 ;get ptr to cpubar into a0
jsr _InitializeBar ;initalize cpu-bar
add.l d4,d1 ;increase y
.no_cpubar
.AllBarsFixed
movem.l (sp)+,d0-a6 ;pop all registers
st.l prg_RenderBarsOk
rts ;return
.Fail
movem.l (sp)+,d0-a6 ;pop all registers
clr.l prg_RenderBarsOk
rts ;return
_InitializeBar
* * * * * * * * * * * * * * * * * * * * *
* *
* Initialize a memory-display bar. *
* *
* IN: a0 - ptr to bar structure. *
* a1 - ptr to window rastport. *
* d0 - x-position. *
* d1 - y-position. *
* d2 - x width. *
* d3 - y height. *
* *
* * * * * * * * * * * * * * * * * * * * *
movem.l d0-a6,-(sp) ;push all registers
move.l a0,a5 ;put ptr to bar in a5
move.l a1,mb_Rport(a5) ;store bar rastport
move.l d0,mb_XPos(a5) ;store bar x-pos
move.l d1,mb_YPos(a5) ;store bar y-pos
move.l d2,mb_XWidth(a5) ;store bar x-width
move.l d3,mb_YHeight(a5) ;store bar y-height
move.l #-1,mb_OldMemFree(a5) ;reset memory-hold
lea.l .BlackBorderVec,a0
move.w d3,2(a0)
move.w d2,8(a0)
lea.l .WhiteBorderVec,a0
move.w d2,(a0)
move.w d2,4(a0)
move.w d3,6(a0)
move.w d3,10(a0)
move.l _IntuitionBase,a6
move.l mb_Rport(a5),a0
lea.l .MemBorder,a1
jsr _LVODrawBorder(a6)
move.l _GfxBase,a6
move.l mb_Rport(a5),a1
move.l #0,d0
jsr _LVOSetAPen(a6)
move.l mb_Rport(a5),a1
move.l mb_XPos(a5),d0
move.l mb_YPos(a5),d1
move.l mb_XWidth(a5),d2
move.l mb_YHeight(a5),d3
add.l d0,d2
add.l d1,d3
subq.l #1,d2
subq.l #1,d3
addq.l #1,d0
addq.l #1,d1
jsr _LVORectFill(a6)
movem.l (sp)+,d0-a6 ;pop all registers
rts ;return
.MemBorder dc.w 0,0
dc.b 1,0,RP_JAM1
dc.b 3
dc.l .BlackBorderVec
dc.l .WhiteBorder
.WhiteBorder dc.w 0,0
dc.b 2,0,RP_JAM1
dc.b 3
dc.l .WhiteBorderVec
dc.l 0
.BlackBorderVec ds.l 3
.WhiteBorderVec ds.l 3
_AddFlushGadget
* * * * * * * * * * * * * * * * * * * * *
* *
* Adds flush-gadgets to the memdisplay *
* window. *
* *
* * * * * * * * * * * * * * * * * * * * *
movem.l d0-a6,-(sp) ;pop all registers
move.l _IntuitionBase,a6 ;put intuitionbase in a6
lea.l _FlushGadgetList,a4 ;get ptr to flushgadget-list into a4
.AddFlushGadgets
move.l (a4)+,a0 ;get ptr to next bar-checkvar
move.l a0,d0 ;put addr in d0
tst.l d0 ;check if it IS a bar-var
beq .NoGadgetsLeft ;end looping if not
move.l (a0),d0 ;get checkvar state
move.l (a4)+,a1 ;get ptr to flush-gadget into a1
move.l (a4)+,a2 ;get ptr to mem-bar into a2
tst.l d0 ;check if bar exist
beq .no_gadget ;skip if not
move.w #GFLG_GADGHBOX,gg_Flags(a1)
move.w #GACT_RELVERIFY,gg_Activation(a1)
move.w #GTYP_BOOLGADGET,gg_GadgetType(a1)
move.l MemoryDisplayWnd,a0 ;put ptr to mem-display window into a0
move.l #0,d0 ;reset d0
move.w mb_XPos+2(a2),d0
add.w #1,d0
move.w d0,gg_LeftEdge(a1)
move.w mb_YPos+2(a2),d0
add.w #1,d0
move.w d0,gg_TopEdge(a1)
move.w mb_XWidth+2(a2),d0
sub.w #1,d0
move.w d0,gg_Width(a1)
move.w mb_YHeight+2(a2),d0
sub.w #1,d0
move.w d0,gg_Height(a1)
jsr _LVOAddGadget(a6) ;add one flush-gadget
.no_gadget
bra .AddFlushGadgets ;loop
.NoGadgetsLeft
movem.l (sp)+,d0-a6 ;push all registers
rts ;return
_RenderMemoryBar
* * * * * * * * * * * * * * * * * * * * *
* *
* Renders a memory-bar. *
* *
* IN: a0 - ptr to memory-bar. *
* d0 - memory available. *
* d1 - largest memory-block. *
* d2 - Total memory. *
* *
* * * * * * * * * * * * * * * * * * * * *
movem.l d0-a6,-(sp) ;push all registers
move.l a0,a5 ;put memory-bar in a5
move.l d0,d5 ;put mem-avail in d5
move.l d1,d6 ;put mem-largest in d6
move.l d2,d7 ;put mem-full in d7
muls.l #100,d5 ;multiplicate mem-avail with 100
divs.l d7,d5 ;divide mem-avail with mem-full
move.w d5,.PercentValue ;store percentage free
move.l mb_XWidth(a5),d3 ;put mem-bar xwidth into d3
muls.l d3,d5 ;multiplicate mem-prc with width
divs.l #100,d5 ;divide with 100
muls.l #100,d6 ;multiplicate mem-largest with 100
divs.l d7,d6 ;divide mem-largest with mem-full
move.l mb_XWidth(a5),d3 ;put mem-bar xwidth into d3
muls.l d3,d6 ;multiplicate mem-prc with width
divs.l #100,d6 ;divide with 100
move.l _GfxBase,a6 ;put gfxbase in a6
move.l mb_Rport(a5),a1 ;put bar rastport into a1
move.l prg_RemaMemBlkColour,d0 ;put remaining mem bar colour in d0
jsr _LVOSetAPen(a6) ;set rastport draw colour
move.l d5,d7 ;put mem-free in d7
sub.l d6,d7 ;subtract mem-largest
tst.l d7 ;check if largest is as large as free
bmi .no_largestblock ;skip if so
move.l mb_Rport(a5),a1 ;put bar rastport into a1
move.l mb_XPos(a5),d0 ;put bar xpos into d0
add.l d6,d0 ;add
move.l mb_YPos(a5),d1
move.l d7,d2
move.l mb_YHeight(a5),d3
add.l d0,d2
add.l d1,d3
addq.l #1,d2
subq.l #1,d3
addq.l #1,d0
addq.l #1,d1
jsr _LVORectFill(a6)
.no_largestblock
move.l _GfxBase,a6
move.l mb_Rport(a5),a1
move.l prg_LargMemBlkColour,d0
jsr _LVOSetAPen(a6)
move.l mb_Rport(a5),a1
move.l mb_XPos(a5),d0
move.l mb_YPos(a5),d1
move.l d6,d2
move.l mb_YHeight(a5),d3
add.l d0,d2
add.l d1,d3
subq.l #1,d3
addq.l #1,d0
addq.l #1,d1
jsr _LVORectFill(a6)
move.l _GfxBase,a6
move.l mb_Rport(a5),a1
move.l #0,d0
jsr _LVOSetAPen(a6)
move.l mb_Rport(a5),a1 ;put mem-display rastport in a1
move.l mb_XPos(a5),d0 ;put bar x-pos in d0
add.l d5,d0 ;add total amount of free mem to d0
move.l mb_YPos(a5),d1 ;put ypos into d1
move.l mb_XPos(a5),d2
add.l mb_XWidth(a5),d2
move.l mb_YHeight(a5),d3
add.l d1,d3
subq.l #1,d2
subq.l #1,d3
addq.l #1,d0
addq.l #1,d1
jsr _LVORectFill(a6) ;clear allocated area
tst.l prg_RenderLines
beq .no_lines
move.l _GfxBase,a6
move.l mb_Rport(a5),a1
move.l _GfxBase,a6
move.l mb_Rport(a5),a1
move.l #1,d0
jsr _LVOSetAPen(a6)
move.l mb_Rport(a5),a1
move.l d6,d0
add.l mb_XPos(a5),d0
move.l mb_YPos(a5),d1
addq.l #1,d1
jsr _LVOMove(a6)
move.l mb_Rport(a5),a1
move.l d6,d0
add.l mb_XPos(a5),d0
move.l mb_YPos(a5),d1
add.l mb_YHeight(a5),d1
subq.l #1,d1
jsr _LVODraw(a6)
move.l mb_Rport(a5),a1
move.l d5,d0
add.l mb_XPos(a5),d0
move.l mb_YPos(a5),d1
addq.l #1,d1
jsr _LVOMove(a6)
move.l mb_Rport(a5),a1
move.l d5,d0
add.l mb_XPos(a5),d0
move.l mb_YPos(a5),d1
add.l mb_YHeight(a5),d1
subq.l #1,d1
jsr _LVODraw(a6)
.no_lines
tst.l prg_RenderPercentage ;check if i should render percents
beq .no_Percentage ;skip if not
clr.l .CharCount ;reset character count
move.l (4).w,a6 ;put execbase in a6
lea.l .PercentMask,a0 ;get ptr to stringmask into a0
lea.l .PercentValue,a1 ;get ptr to percentage into a1
lea.l .parse_PercentString,a2 ;put ptr to output routine into a2
lea.l .PercentString,a3 ;put pointer to output string into a3
jsr _LVORawDoFmt(a6) ;generate percentage string
move.l _GfxBase,a6 ;put gfxbase in a6
move.l mb_Rport(A5),a1 ;put bar rastport in a1
lea.l .PercentString,a0 ;get pointer to percent string into a0
move.l .CharCount,d0 ;put number of chars into d0
sub.l #1,d0 ;get correct size
jsr _LVOTextLength(a6) ;evaluate text-string width
lsr.l #1,d0 ;halven width
move.l d0,d6 ;store text-centered width
move.l MemoryDisplayWnd,a4 ;put ptr to mem-display window in a4
move.l wd_IFont(a4),a3 ;put pointer to window font in a3
move.l mb_YHeight(a5),d2 ;get memory-bar y-height into d2
sub.l #2,d2 ;make sure there is space left on bar
cmp.w tf_YSize(a3),d2 ;check if font height is larger than the bar
blo .no_Percentage ;skip if font is larger
move.l _GfxBase,a6 ;put gfxbase in a6
move.l mb_Rport(a5),a1 ;put mem-display rastport in a1
* WARNING! I DO WORD ACCESS WITH THE BAR
* POSITION AND SIZE COUNTERS HERE! I GET
* PAST A FEW NASTY BUGS THAT WAY!
* center x-axis
move.w mb_XPos+2(a5),d0 ;put bar x-pos in d0
sub.w d6,d0 ;sub text-centered width
move.w mb_XWidth+2(a5),d2 ;get bar width in d2
lsr.w #1,d2 ;divide by 2
add.w d2,d0 ;add half bar width to text-pos
* centre y-axis
move.w mb_YPos+2(a5),d1 ;put bar y-pos in d1
add.w tf_Baseline(a3),d1 ;add window-font baseline
move.w mb_YHeight+2(a5),d2
lsr.w #1,d2
add.w d2,d1
move.w tf_YSize(a3),d2
lsr.w #1,d2
sub.w d2,d1
addq.w #1,d1
jsr _LVOMove(a6) ;set gr-coordinates
move.l _GfxBase,a6 ;put gfxbase in a6
move.l mb_Rport(a5),a1 ;put rastport in a1
move.l #RP_JAM1,d0 ;use JAM1 draw mode
jsr _LVOSetDrMd(a6) ;set drawmode
move.l mb_Rport(a5),a1
move.l #1,d0
jsr _LVOSetAPen(a6) ;set
move.l mb_Rport(a5),a1 ;put mem-display rastport in a1
lea.l .PercentString,a0 ;put string in a0
move.l .CharCount,d0 ;put number of chars to be output
subq.l #1,d0 ;get correct amount of chars
jsr _LVOText(a6) ;write percentage
.no_Percentage
movem.l (sp)+,d0-a6 ;pop all registers
rts ;return
.parse_PercentString
move.b d0,(a3)+ ;output next char
add.l #1,.CharCount ;increase char-counter
rts
.PercentMask dc.b "%d%%",0
.PercentValue ds.l 1
.CharCount ds.l 1
.PercentString ds.b 6
_BarList
dc.l prg_ChipDisplayed,prg_ChipmemBar,MEMF_CHIP,FALSE
dc.l prg_FastDisplayed,prg_FastmemBar,MEMF_FAST,FALSE
dc.l prg_PublicDisplayed,prg_PublicmemBar,0,FALSE
dc.l prg_CPUDisplayed,prg_CPUUsageBar,0,prg_CPUUsage
dc.l 0
_FlushGadgetList
dc.l prg_ChipDisplayed,ChipFlushGadget,prg_ChipmemBar
dc.l prg_FastDisplayed,FastFlushGadget,prg_FastmemBar
dc.l prg_PublicDisplayed,PublicFlushGadget,prg_PublicmemBar
dc.l 0
section bss,bss ;availmem bss section
* program variables
prg_RenderBarsOk ds.l 1 ;program renderbars bool
* program flush gadgets
ChipFlushGadget ds.b gg_SIZEOF
FastFlushGadget ds.b gg_SIZEOF
PublicFlushGadget ds.b gg_SIZEOF
* program memorybar structures
prg_ChipmemBar ds.b mb_SIZEOF
prg_FastmemBar ds.b mb_SIZEOF
prg_PublicmemBar ds.b mb_SIZEOF
prg_CPUUsageBar ds.b mb_SIZEOF